<template>
	<div class="rank-detail">
		<musicList :title="title" :bg-image="bgImage" :songs="songs" :rank="true"></musicList>
	</div>
</template>

<script>
import { mapGetters } from 'vuex'
import { ERR_OK } from 'api/config'
import musicList from 'base/musicList/musicList'
import { getMusicList } from 'api/rank'
import { createSong } from 'assets/js/song'

export default {
	components: {
		musicList
	},
	computed: {
    title() {
      // console.log(JSON.stringify(this.topList))
      return this.topList.topTitle
    },
    bgImage() {
      return this.topList.picUrl
    },
    ...mapGetters(["topList"])
  },
  data() {
    return {
      songs: []
    }
  },
  created() {
    this._getTopList()
	},
	methods: {
    _getTopList() {
      var that = this
      if (!this.topList.id) {
        this.$router.push("/rank")
        return
      }
      getMusicList(this.topList.id).then(res => {
        if (res.code === ERR_OK) {
          that.songs = that._normalSongs(res.songlist)
        }
      })
    },
    _normalSongs(list) {
      let ret = [];
      list.forEach(item => {
        const musicData = item.data
        if (musicData.songid && musicData.albummid) {
          // 必须有id和连接码
          ret.push(createSong(musicData))
        }
      });
      return ret
    }
  }
}
</script>

<style lang="scss" scoped>
@import "@/assets/css/mixin.scss";
.rank-detail {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  background: $background-color;
  z-index: 301;
}
</style>